# -*- coding: utf-8 -*-  
'''
拿样本标签质心
    k-means++

@author: luoyi
Created on 2021年3月14日
'''
import numpy as np

import utils.conf as conf
import data.dataset_anchor as ds_anchor
import data.dataset as ds


anchor_creator = ds_anchor.AnchorCreator(k=9, show_log=False)


#    数据集
data_iterator = ds.data_iterator(img_dir=conf.DATASET.get_in_train(), 
                                 label_path=conf.DATASET.get_label_train(), 
                                 is_mutiple_file=conf.DATASET.get_label_train_mutiple(), 
                                 count=conf.DATASET.get_count_train())

#    选取质心
centroids = anchor_creator.election(data_iterator, num_sample=1000)
print('最具代表的k个质心：')
centroids = centroids[np.argsort(centroids[:, 4])]
for centroid in centroids:
    print(centroid)
    pass

print('转换为高宽属性：')
centroids_w = centroids[:, 2] - centroids[:, 0]
centroids_h = centroids[:, 3] - centroids[:, 1]
centroids = np.stack([centroids_h, centroids_w], axis=-1)
for centroid in centroids:
    print(centroid)
    pass